package com.example.listviewtest;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.example.taobao.R;

import java.util.List;

public class GoodsAdapter extends RecyclerView.Adapter<GoodsAdapter.ViewHolder> {

   private List<Goods> data;
   private Context context;

    public GoodsAdapter(List<Goods> goodsList, MainActivity mainActivity) {

    }

//   public GoodsAdapter(List<Goods> data,Context context) {
//        this.data=data;
//        this.context=context;
//    }

    @NonNull
    @Override
    public GoodsAdapter.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view=View.inflate(context,R.layout.goods_item,null);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull GoodsAdapter.ViewHolder holder, int position) {
       holder.tv.setText(data.get(position).getName());
    }

    @Override
    public int getItemCount() {
       return data==null?0: data.size();
    }

    public static class ViewHolder extends RecyclerView.ViewHolder{
        private final TextView tv;

        public ViewHolder(@NonNull View itemView){
            super(itemView);
            tv=itemView.findViewById(R.id.tv);
        }

    }
}
